<?php

class PeopleResultSet
{
	private $People = array();
	private $Sort = "Surname";
	private $PeopleGroups = array();
	
	public function __construct($peopleGroups)
	{
//		print_r($peopleGroups);
		$this->PeopleGroups = $peopleGroups;
//		print_r ($this->PeopleGroups);
	}
	
	public function getPeople()
	{
//		print_r ($this->PeopleGroups);
		$database=$GLOBALS['DATABASE']->Recopy();
		$sql = "SELECT DISTINCT p.PersonID FROM MusicAdmin_People AS p ";
		$sql .= "LEFT JOIN MusicAdmin_Groups as g ON p.PersonID = g.PersonID  ";
		if(count($this->PeopleGroups))
		{
			$sql .= "WHERE ";
			foreach ($this->PeopleGroups as $pGroup)
			{
				$sql .= "g.GroupNameID = ".$pGroup." OR ";
			}
			$sql = substr($sql,0,-3);
		}
		$sql .= "ORDER BY ".$this->Sort;
//		echo $sql;
		$database->executeSQL($sql);
		while($row=$database->getRow())
		{
			$person=new Person($row['PersonID']);
			array_push($this->People,$person);
		}
		return $this->People;
	}
	
	public function setSort($sort){$this->Sort = $sort;}
}
